package controller;


import entity.LanguageCategory;
import entity.Video;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import service.LanguageService;
import service.VideoService;
import utils.Page;

import java.util.List;


/**
 * @Description
 * @Author 李楚鹏
 * @Date 2024/12/30 下午4:30
 **/
@Controller
@RequestMapping("/main/user")
public class VideoController {
    @Autowired
    private VideoService videoService;
    @Autowired
    private LanguageService languageService;
    // 映射到/home路径的请求
    @RequestMapping("/page")
    public String page(Model model, Video condition,
                       @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                       @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize
            , HttpSession httpSession) {
        Page<Video> page = null;
        try {
            // 查询用户的分页信息
            page = videoService.findPage(condition, pageNo, pageSize);
            // 查询所有的角色信息
            List<LanguageCategory> roleList = languageService.findAll();
            // 将分页数据、角色列表和查询条件设置到模型数据中
            model.addAttribute("pageInfo", page);
            model.addAttribute("roleList", roleList);
            model.addAttribute("condition", condition);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return "index";
    }
}
